// components/workerAcPop/workerAcPop.js
Component({
  emits: ['close','confirm'],
  /**
   * 组件的属性列表
   */
  properties: {
    popupitem: {
      type: Object,
      default () {
        return {title:'',user:{}};
      }
    },
    timearea: {
      type: Object,
      default () {
        return {timeDay:[],timeTime:[]};
      }
    },
    show: {
      type: Boolean,
      default: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    showTime:false,
    timeDayIndex:0,
    timeTimeIndex:0,
    shareList: [{
      share: [{
        name: "补差价",
        icon: "wealth-fill",
        color: "#e54d42",
        size: 34
      }, {
        name: "调整时间",
        icon: "clock-fill",
        color: "#07c160",
        size: 36
      }, {
        name: "放弃服务",
        icon: "dissatisfied",
        color: "#ff7900"
      }]
    }, {
      operate: [{
        name: "争议反馈",
        icon: "warning",
        size: 30
      }, {
        name: "刷新",
        icon: "refresh",
        size: 30
      }]
    }]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    setTDI(e) {
      this.setData({
        timeDayIndex:e.currentTarget.dataset.index
      })
    },
    setTDI2(e) {
      this.setData({
        timeTimeIndex:e.currentTarget.dataset.index
      })
    },
    popup() {
      this.popupTime();
      this.triggerEvent('close');
    },
    popupTime(){
      this.setData({
        showTime:false
      })
    },
    reload(){
      this.triggerEvent('confirm', {type:"刷新"});
    },
    async setTime(){
      let sub={};
      sub.sn=this.data.popupitem.sn;
      sub.day=this.data.timearea.timeDay[this.data.timeDayIndex].v;
      sub.time=this.data.timearea.timeTime[this.data.timeTimeIndex];
      this.popup();
      await wx.util.post("task/edit_time",sub,false);
      wx.util.toast('修改成功');
      this.reload();
    },
    async giveUpOrder(){
      await wx.util.post("task/giveup",this.data.popupitem,false);
      wx.util.toast('操作成功');
      this.reload();
    },
    async acTap(e){
      let item=e.currentTarget.dataset.item;
      if(item.name=="争议反馈"){
        wx.util.toast('请联系客服反馈');
        return;
      }
      if(item.name=="补差价"){
        this.popup();
        wx.navigateTo({
          url:"/pages/workerCode/done?sn="+this.data.popupitem.sn
        })
        return;
      }
      if(item.name=="放弃服务"){
        this.popup();
        await wx.util.confirm("是否确认放弃该订单？",this.data.popupitem.title+' / '+this.data.popupitem.user.name);
        this.giveUpOrder();
        return;
      }
      if(item.name=="调整时间"){
        this.setData({
          showTime:true
        })
        return;
      }
      if(item.name=="刷新"){
        this.popup();
        this.reload();
        return;
      }
      this.popup();
    }
  }
})